#include<iostream>
#include<vector>
#include<climits>
using namespace std;

int maxProfit(vector<int>& prices) 
{
	int n=prices.size();
	vector<vector<int>> Sold(n+1,vector<int>(3));
	vector<vector<int>> Hold(n+1,vector<int>(3,INT_MIN));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=2;j++)
		{
			Sold[i][j]=max(Sold[i-1][j],Hold[i-1][j]+prices[i-1]);
			Hold[i][j]=max(Hold[i-1][j],Sold[i-1][j-1]-prices[i-1]);
		}
	}

	return max(Sold[n][1],Sold[n][2]);
}

int main()
{
	int n,k;cin>>n>>k;
	vector<int>prices(n);
	for(int i=0;i<n;i++)
	{
		cin>>prices[i];
	}
	cout<<maxProfit(prices)<<endl;
}